package com.limi.java8.streams.practice;

import com.limi.java8.lambda.practice.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @Description: TODO
 * @Author Limi Pan
 * @Date 2018-10-23 21:35
 * @Version v1.0
 */
public class StreamPractice {
    /*
     * 1、给定一个数字列表，如何返回一个由每个数的平方构成的列表呢？
     * 给定[1,2,3,4,5],应该返回[1,4,9,16,25]
     */
    @Test
    public void test1(){
        Integer[] num = {1, 2, 3, 4, 5};
        Arrays.stream(num)
                .map(e -> e * e)
                .forEach(System.out::println);
    }

    /*
     * 2、怎样用map和reduce方法数一数流中有多少个Employee呢？
     */
    List<Employee> employees = Arrays.asList(
            new Employee("张三", 18, 8888.30, Employee.Status.FREE),
            new Employee("李四", 24, 12578.82, Employee.Status.BUSY),
            new Employee("王五", 23, 4623.96, Employee.Status.VOCATION),
            new Employee("赵六", 25, 6578.94, Employee.Status.FREE),
            new Employee("蒋七", 31, 9578.94, Employee.Status.BUSY),
            new Employee("蒋七", 31, 9578.94, Employee.Status.BUSY)
    );
    @Test
    public void test2(){
        Optional<Integer> count = employees.stream()
                .map(e -> 1)
                .reduce(Integer::sum);
        System.out.println(count.get());
    }
}
